<template>
  <div class="card-list">
    <a-row :gutter="24">
      <a-col :xl="24" :lg="24" :md="24" :sm="24" :xs="24">
        <a-card
          class="project-list"
          style="margin-bottom: 24px;"
          :bordered="true"
          :title="msg+'列表'"
          :body-style="{ padding: 0 }"
        >
          <a-list rowKey="id" :grid="{ lg: 3, md: 2, sm: 1, xs: 1}" :dataSource="dataSource">
            <a-list-item slot="renderItem" slot-scope="item">
              <template v-if="!item || item.id === undefined">
                <a-button class="new-btn" type="dashed">
                  <a-icon type="plus" />新增运动员
                </a-button>
              </template>
              <template v-else>
                <a-card :hoverable="true" :key="item.id">
                  <a-card-meta @click="tabChange(item)">
                    <a slot="title">{{ item.title }}</a>
                    <a-avatar class="card-avatar" slot="avatar" :src="item.avatar" size="large" />
                    <div class="meta-content" slot="description">{{ item.content }}</div>
                  </a-card-meta>
                  <template class="ant-card-actions" slot="actions">
                    <a>配置管理员</a>
                    <a>删除</a>
                  </template>
                </a-card>
              </template>
            </a-list-item>
          </a-list>
        </a-card>
      </a-col>
      <a-col v-if="$route.params.params==3" :xl="12" :lg="24" :md="24" :sm="24" :xs="24">
        <a-card title="训练情况" :bordered="true">占位</a-card>
      </a-col>
      <a-col v-if="$route.params.params==3" style="padding: 0 12px" :xl="12" :lg="24" :md="24" :sm="24" :xs="24">
        <a-card title="队内成绩" :bordered="true">占位</a-card>
      </a-col>
    </a-row>
  </div>
</template>

<script>
export default {
  mounted() {
    //获取当前路由参数
    const flag = parseInt(this.$route.params.params);
    switch (flag) {
      //这里根据登录拿到用户信息,发送第一次请求获得初始数据,然后在每次切换卡片的时候发送请求获得数据,我们不关心路径,我们只关心
      //每次切换卡片的时候拿到的数据
      case 1:
        this.dataSource.push({});
        this.msg="项目"
        for (let i = 1; i <= 4; i++) {
          this.dataSource.push({
            id: i,
            title: `第${i}项体育项目`,
            avatar: "../../assets/logo.png",
            content: "我是举重/游泳/跳远之一"
          });
        }
        break;
      case 2:
        this.dataSource.push({});
        this.msg="队伍"
        for (let i = 1; i <= 4; i++) {
          this.dataSource.push({
            id: i,
            title: `第${i}个队伍`,
            avatar: "../../assets/logo.png",
            content: "我是队伍1/2/3/4..."
          });
        }
        break;
      case 3:
        this.dataSource.push({});
        this.msg="运动员"
        for (let i = 1; i <= 4; i++) {
          this.dataSource.push({
            id: i,
            title: `第${i}个运动员`,
            avatar: "../../assets/logo.png",
            content: "我是运动员1/2/3/4..."
          });
        }
        break;
    }
  },
  name: "CardList",
  data() {
    return {
      dataSource: [],
      msg:''
    };
  },
  methods: {
    // eventBail(e) {
    //   console.log(e.target.childNodes.parentNode);

    //   let name = e.target.nodeName.toLowerCase();
    //   if (name != "a") {
    //   }
    // },
    tabChange(item) {
      //   console.log(e.target);

      const flag = parseInt(this.$route.params.params);
      console.log(item.id);
      //   let str = e.target.innerText;
      //   let num = str.match(/\d/g);
      //   console.log(num);

      switch (flag) {
        case 1:
          this.$router.push({ name: "sports", params: { params: 2 } });
          break;
        case 2:
          this.$router.push({ name: "sports", params: { params: 3 } });
          break;
        case 3:
          this.$router.push({ name: "account" });
          break;
        default:
          break;
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.card-list {
  /deep/ .ant-card-body:hover {
    .ant-card-meta-title > a {
      color: #aaabac;
    }
  }

  /deep/ .ant-card-meta-title {
    margin-bottom: 12px;

    & > a {
      display: inline-block;
      max-width: 100%;
      color: rgba(0, 0, 0, 0.85);
    }
  }

  /deep/ .meta-content {
    position: relative;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    height: 64px;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    margin-bottom: 1em;
  }
}

.card-avatar {
  width: 48px;
  height: 48px;
  border-radius: 48px;
}

.ant-card-actions {
  background: #f7f9fa;

  li {
    float: left;
    text-align: center;
    margin: 12px 0;
    color: rgba(0, 0, 0, 0.45);
    width: 50%;

    &:not(:last-child) {
      border-right: 1px solid #e8e8e8;
    }

    a {
      color: rgba(0, 0, 0, 0.45);
      line-height: 22px;
      display: inline-block;
      width: 100%;
      &:hover {
        color: #aaabac;
      }
    }
  }
}

.new-btn {
  background-color: #fff;
  border-radius: 2px;
  width: 100%;
  height: 188px;
}
</style>
